package com.guowen.myaccount.utils;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import androidx.annotation.NonNull;

import com.guowen.myaccount.R;
import com.guowen.myaccount.adapter.AccManagementAdapter;
import com.guowen.myaccount.db.AccManageBean;
import com.guowen.myaccount.db.DBManager;

import java.util.List;

public class TranAccountDialog extends Dialog {

    private List<AccManageBean> mDatas;
    private ListView tranAccLv;
    private AccManagementAdapter adapter;

    private OnEnsureListener onEnsureListener;
    // 设定回调接口的方法
    public void setOnEnsureListener(OnEnsureListener onEnsureListener) {
        this.onEnsureListener = onEnsureListener;
    }

    public interface OnEnsureListener{
        public void onEnsure(AccManageBean bean);
    }



    public TranAccountDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_tran_account);

        tranAccLv = findViewById(R.id.dialog_tran_account_lv);
        mDatas = DBManager.getAccManList();
        adapter = new AccManagementAdapter(getContext(),mDatas);
        tranAccLv.setAdapter(adapter);

        tranAccLv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                AccManageBean bean = mDatas.get(position);
                if (onEnsureListener != null){
                    onEnsureListener.onEnsure(bean);
                }
                cancel();
            }
        });
    }
}
